import {baseUrl} from './config.js'
export default {
	config: {
		baseUrl: baseUrl,
		header: {
			'Content-Type': 'application/json'
		},  
		data: {},
		method: "GET",
		// dataType: "json",  /* 如设为json，会对返回的数据做一次 JSON.parse */
	},
	request(options) {
		if (!options) {
			options = {}
		}
		options.baseUrl = options.baseUrl || this.config.baseUrl
		options.header = options.header || this.config.header
		// options.dataType = options.dataType || this.config.dataType
		options.url = options.baseUrl + options.url
		options.data = options.data || {}
		options.method = options.method || this.config.method
	   
		return new Promise((resolve, reject) => {
				uni.request({
					...options,
					success:(res)=>{
						// console.log(99999999999,res)
						if(res.statusCode != 200){
							return reject();
						}
						resolve(res);
					}
				})	
				
		});
	 },
	 get(url, data, options) {
	 	if (!options) {
	 		options = {}
	 	}
	 	options.url = url
	 	options.data = data
	 	options.method = 'GET'  
		
	 	return this.request(options)
	 },
	 post(url, data, options) {
	 	if (!options) {
	 		options = {}
	 	}
	 	options.url = url
	 	options.data = data
	 	options.method = 'POST'
	 	return this.request(options)
	 },
}
